<?php
class AddMenuAction extends CommonAction {

	public function add(){
		
			
			 $menu = M("menu");
			 $menu->MENU_NAME=$_GET["MENU_NAME"];
			 $menu->MENU_ORDER=$_GET["MENU_ORDER"];
			 $menu->UPERMENUID='0';
			 $result=$menu->add();
			if ($result){
			
			// 成功后返回客户端新增的用户ID，并返回提示信息和操作状态
			   $this->ajaxReturn(1,"新增成功！",1);
			   
			}else{
				
			// 错误后返回错误的操作状态和提示信息
			   $this->ajaxReturn(0,'xxx',0);
			   
			}
	}
	
	public function deleteMenu(){
		
			 
			 $menu = M("menu");
			
			 $id=$_GET['menuid'];
			 
			 $result = $menu->where("menu_id=$id")->delete(); // 删除所有状态为0的用户数据
			 
			  $this->ajaxReturn(1,"删除成功！",1);
	}
	public function editMenuContent(){
		
			 
			 $menu = M("menu_content");
			
			 $menuid=$_POST['CONTENT_ID'];
			 
			 $content=stripslashes($_POST['CONTENT']);
			 
			 $data["MENU_CONTENT"]=$content;
			 
			 
			 $result = $menu->where("content_id=$menuid")->find(); 
			 
			 if($result){
			 	
			 	$menu->where("content_id=$menuid")->save($data);
			 	
			 }else{
			 	$menu->MENU_ID=$_POST['menuID'];
			 	$menu->MENU_CONTENT=$_POST['menuID'];
			 	$menu->add();
			 }
			  $this->ajaxReturn(1,"修改成功！",1);
	}
	
	public function getSecondLevelMenu(){
		
			 
			 $menu = M("menu");
			
			 $id=$_GET['menuid'];
			 
			 
			 $result = $menu->where("UPERMENUID=$id")->select(); // 删除所有状态为0的用户数据
			 
			  $this->ajaxReturn($result,"查询二级菜单成功！",1);
	}
	
	public function getThirdLevelMenu(){
		
			 
			 $menu = M("menu");
			
			 $id=$_GET['menuid'];
			 
			 
			 $result = $menu->where("UPERMENUID=$id")->select(); // 删除所有状态为0的用户数据
			 
			  $this->ajaxReturn($result,"查询二级菜单成功！",1);
	}
	
	
		public function addLevelTwo(){
			
			 $parentID=$_GET["parentID"];
			 $menu = M("menu");
			 $menu->MENU_NAME=$_GET["MENU_NAME"];
			 $menu->MENU_ORDER=$_GET["MENU_ORDER"];
			 $menu->UPERMENUID=$parentID;
			 $result=$menu->add();
			if ($result){
			
			// 成功后返回客户端新增的用户ID，并返回提示信息和操作状态
			   $this->ajaxReturn(1,"新增成功！",1);
			   
			}else{
				
			// 错误后返回错误的操作状态和提示信息
			   $this->ajaxReturn(0,'xxx',0);
			   
			}
	}
	
	public function getSubMenu(){
		
			
			 $menu = M("menu");
			 
			 $upperid=$_GET["upperid"];
			 
			 
			 
			 $result = $menu->where("UPERMENUID=$upperid")->join('LEFT JOIN think_menu_content ON think_menu.menu_id = think_menu_content.menu_id')->order('MENU_ORDER')->select(); // 删除所有状态为0的用户数据
			 
			 $this->ajaxReturn($result,"查询二级菜单成功！",1);
	}
	
	public function showDetail(){
		
		 $menu = M("menu_content");
			
			 $menuid=$_GET['menuid'];
			 
			 $result = $menu->where("menu_id=$menuid")->find(); 
			 
			 
			  $this->ajaxReturn($result,"查询二级菜单成功！",1);
	}
}
?>
